var goodsViewCtrl = new XFApp.client();
XFApp.client.prototype.goodsView = {
	urlItems : {
		loadGoodsClassURL:basePath+"/nt/packageForstats/goodsRecord/loadGoodsClass"
	},	
	event : function(){
		
	},
	initViewByGoods : function(){
		var goods_status = "";
		$("#add_btn").attr("href",basePath+"/nt/packageForstats/goodsRecord/viewAdd?itemNo="+sku_goods.itemno);
		for(index in stats_goodsStatus){
			var goodsStatus = stats_goodsStatus[index];
			if(goodsStatus.dictCode == sku_goods.docketstatus ){
				goods_status = goodsStatus.dictName;
			}
		}
		$("#docketstatus").text(goods_status);
		var apply_status = "";
		for(index in stats_approves){
			var approves = stats_approves[index];
			if(approves.dictCode == sku_goods.applystatus){
				apply_status = approves.dictName;
			}
		}
		$("#applystatus_des").text(apply_status);
	
		var currency_des = "";
		for(index in currencys){
			var currency = currencys[index];
			if(currency.dictCode == sku_goods.currency){
				currency_des = currency.dictName;
			}
		}
		$("#currency").text(currency_des);
		
		var unit_des = "";
		var unit_des1 = "";
		var unit_des2 = "";
		for(index in units){
			var unit = units[index];
			if(unit.dictCode == sku_goods.unit){
				unit_des = unit.dictName;
			}
			if(unit.dictCode == sku_goods.unit1){
				unit_des1 = unit.dictName;
			}
			if(unit.dictCode == sku_goods.unit2){
				unit_des2 = unit.dictName;
			}
		}
		$("#unit").text(unit_des);
		$("#unit1").text(unit_des1);
		$("#unit2").text(unit_des2);
		
		var customer_des = "";
		for(index in customerCodes){
			var customer = customerCodes[index];
			if(customer.dictCode == sku_goods.customscode){
				customer_des = customer.dictName;
			}
		}
		$("#customSelect").text(customer_des);
		$("#brand").text(sku_goods.brand);
		$("#gmodel").text(sku_goods.gmodel);
		
		$("span").each(function(){
			var val = "";
			if(!!sku_goods[$(this).attr("name")]){
				val = sku_goods[$(this).attr("name")];
			}
			if($(this).hasClass("dataTime") && !!val){
				val = val.replace("T"," ");
			}
			if(!!val){
				$(this).text(val);
			}
		});
		
		var mainCode = sku_goods["mainClassDictCode"];
		var mainName = this.selClassValue(classDictDataId,mainCode);
		$("#mainClassDictCode").text(mainName);
		var subDictData = this.loadGoodsClass(mainCode,mainName);
		$("#classDictDataId").text(this.selClassValue(subDictData,sku_goods["classDictDataId"]));
	},
	selClassValue : function(classData,val){
		var text ;
		for(index in classData){
			var cls = classData[index];
			if(cls.dictCode == val){
				text = cls.dictName;
			}
		}
		return text;
	},
	loadGoodsClass : function(goodsDictCode,goodsDictName){
		var subClassData = null;
		var _this = this;
		var params = {
				goodsDictCode:goodsDictCode,
				goodsDictName:goodsDictName
		}
		$.ajax({			   
			url:_this.urlItems.loadGoodsClassURL,
			data:params,
			dataType:'json',
			type:'post',
			async:false,
			success:function(data){
				if(data.code!=10000){
					webDialogUtil.simpleAlert("查询子类商品失败", "温馨提示");
				}else{
					var classDictData = data.result;
					var newClassDictData = [];
					for(var index = 0;index<classDictData.length;index++){
						var data = classDictData[index];
						
						var newData = {
								dictCode:data.dictCode,
								dictName:data.dictName
						}
						newClassDictData.push(newData);
					}
				    subClassData = newClassDictData;
				}
			},
			error:function(data){
				webDialogUtil.simpleAlert("查询子类商品异常", "温馨提示");
			}
		});
		return subClassData;
	},
	goBack:function(){
		goodsViewCtrl.clearCookie(cookieHistoryBackParamsName,"/");
		window.location.href=basePath+"/nt/packageForstats/goodsStats";
	}
}

$(function(){
	goodsViewCtrl.goodsView.event();
	if(!!historyBackParams){
		var jsonObjStr = JSON.stringify(historyBackParams);
		goodsViewCtrl.setCookie(cookieHistoryBackParamsName, jsonObjStr,1,"/");
	}
	if(!!sku_goods){
		goodsViewCtrl.goodsView.initViewByGoods();
	}
});